package router

import (
	"3-19yk/client/client"
	"3-19yk/client/enit"
	"3-19yk/client/response"
	"3-19yk/common/proto/user"
	"github.com/gin-gonic/gin"
)

func OrderAdd(c *gin.Context) {
	ui := c.GetUint("userId")
	var data enit.OrderAdd
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	add, err := client.OrderAdd(c, &user.OrderAddReq{
		UserId:       int64(ui),
		ScenicId:     int64(data.ScenicId),
		RealNameId:   int64(data.RealNameId),
		AmdNum:       int64(data.AdmNum),
		AdmPeopleNum: int64(data.AdmPeopleNum),
		SelectData:   int64(data.SelectData),
		AdmStatus:    int64(data.AdmStatus),
	})
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	response.ResPonseSuccess(c, add)
}
func OrderCall(c *gin.Context) {
	out_trade_no := c.Request.FormValue("out_trade_no")
	trade_status := c.Request.FormValue("trade_status")
	call, err := client.OrderCall(c, &user.OrderCallReq{
		OrderSn:     out_trade_no,
		OrderStatus: trade_status,
	})
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	response.ResPonseSuccess(c, call)
}

func OrderShow(c *gin.Context) {
	var data enit.OrderShow
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	show, err := client.OrderShow(c, &user.OrderShowReq{Id: int64(data.Id)})
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	response.ResPonseSuccess(c, show)
}

func InCure(c *gin.Context) {
	
	ui := c.GetUint("userId")
	var data enit.InCure
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	cure, err := client.InCure(c, &user.InCureReq{
		UserId:   int64(ui),
		ScenicId: int64(data.ScenicId),
		OrderId:  int64(data.OrderId),
	})
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	response.ResPonseSuccess(c, cure)
}
